package com.guxingke.typecho4j.widget.handle.comment;

import com.guxingke.typecho4j.Typecho4jException;
import com.guxingke.typecho4j.route.DispatcherStrategy;
import com.guxingke.typecho4j.route.Route;
import com.guxingke.typecho4j.route.Routes;
import com.guxingke.typecho4j.widget.WidgetHandle;
import com.guxingke.typecho4j.widget.provider.CommentBaseWidget;
import com.guxingke.typecho4j.widget.provider.ProviderWidget;
import com.guxingke.typecho4j.widget.provider.comment.CommentsManageWidget;
import com.guxingke.typecho4j.widget.provider.comment.CommentsWidget;
import com.guxingke.typecho4j.widget.provider.comment.RecentCommentsWidget;
import com.jfinal.core.Controller;

/**
 * 新增评论处理组件
 * 
 * @author guxingke
 * */
public class deleteCommentHandleWidget extends CommentBaseWidget implements
		WidgetHandle {

	@Override
	public void handle(Controller controller) throws Typecho4jException {
		String[] coids = controller.getParaValues("coid[]");

		Long coid = null;
		for (String string : coids) {
			coid = Long.parseLong(string);
			deleteComment(coid);
		}

		ProviderWidget.refreshProviderWidget(CommentsWidget.class);
		ProviderWidget.refreshProviderWidget(CommentsManageWidget.class);
		ProviderWidget.refreshProviderWidget(RecentCommentsWidget.class);
	}

	@Override
	public void configRoute(Routes routes) {
		Route commentRoute = new Route("deleteComments",
				this.getClass(), "/admin/manage-comments",
				DispatcherStrategy.REDIRECT);
		routes.addRoute(commentRoute);
	}
}
